package br.com.dev.tcc.view;

import java.util.List;

import android.app.Activity;
import android.view.View.OnClickListener;
import android.widget.TextView;
import br.com.dev.tcc.R;
import br.com.dev.tcc.bean.BaseItem;

import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.SubMenu;

/**
 * View da tela inicial, contem uma grade, sabe construir um submenu de
 * actionbar e possui um layout para avisos.
 * 
 * @see GridBaseView
 */
public class HomeView extends GridBaseView {

	public HomeView(Activity activity) {
		super(activity);
	}

	/**
	 * Constroi um submenu de acordo com os itens recebidos
	 * 
	 * @param menu
	 * @param itens
	 * @return menu com os itens recebidos
	 */
	public Menu buildTelefonesMenu(Menu menu, List<BaseItem> itens) {

		SubMenu subMenu = menu.addSubMenu(null);

		for (BaseItem item : itens) {

			subMenu.add(item.getText())//.setIcon(item.getIcon())
					.setIntent(item.getIntent());
		}

		MenuItem menuItem = subMenu.getItem();
		menuItem.setIcon(android.R.drawable.ic_menu_call);
		menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
		menuItem.setTitle(R.string.discar_menu);

		return menu;
	}

	/**
	 * @param text
	 *            texto exibido no layout de aviso
	 */
	public void setAlertText(String text) {

		((TextView) activity.findViewById(R.id.tvAviso)).setText(text);
	}

	/**
	 * Registra um listener para ser chamado quando ocorrer clique no layout de
	 * aviso de estado do gps
	 * 
	 * @param listener
	 */
	public void setAlertClickListener(OnClickListener listener) {

		activity.findViewById(R.id.layoutAviso).setOnClickListener(listener);
	}
}
